package day04

object ImplicitContext {

  implicit object OrderedGirl extends Ordering[Girl] {
    override def compare(x: Girl, y: Girl): Int = {
      if (x.faceValue > y.faceValue) {
        1
      } else {
        -1
      }
    }
  }

}

class Girl(val name: String, var faceValue: Int) {
  override def toString: String = s"name:$name,faceValue:$faceValue"
}
object Girl {
  def apply(name: String, faceValue: Int): Girl = new Girl(name, faceValue)
}


object Goddess {
  def main(args: Array[String]): Unit = {
    val girlA = Girl("张三", 90)
    val girlB = Girl("李四", 180)
    import ImplicitContext.OrderedGirl
    val goddess = new Goddess[Girl](girlA,girlB)
    println(goddess.choose())
  }
}

class Goddess[T:Ordering](val param1:T,val param2:T){
  def choose()(implicit ord:Ordering[T]) = {
    if (ord.gt(param1,param2)){
      param1
    }else{
      param2
    }
  }
}